/**dup ,dup2*/
#include<errno.h>
#include<stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
int main(void)
{
	int fd1,fd2,ret;
	char buf[1024];
	fd1=open("test.txt",O_RDWR| O_TRUNC);
	if(-1==fd1){
		perror("open1 error");
		return 1;
	}
	//fd2=dup(fd1);
	fd2=dup2(fd1,1000);
	printf("new fd:%d\n",fd2);
	if(-1==fd2){
		perror("dup error");
		close(fd1);
		return 1;
	}
	ret=write(fd1,"hello world\n",12);
	if(-1==ret){
		perror("wrete error");
		close(fd2);
		close(fd1);
		return 1;
	}
	lseek(fd2,0,SEEK_SET);
	ret=read(fd1,buf,12);
	if(-1==ret){
		perror("read error");
		close(fd1);
		close(fd2);
		return 1;
	}
	printf("read: %s\n",buf);
	close(fd1);
	close(fd2);
	return 0;
}
